﻿using NUnit.Framework;
using Myotragus.Data.Registration;
using Myotragus.Data.Domain;
using System.Linq;
using Myotragus.Data.Repositories;
using Myotragus.Data.Criteria;

namespace Myotragus.Data.Tests.Tests.Registration
{
	[TestFixture]
	public class RegistrationFixtures
	{
		[SetUp]
		public void SetUp()
		{ }

		[Test]
		public void Services()
		{
			var all = ServicesImplementation.FromAssemblyContaining<IEntity>();

			Assert.IsTrue(all.Any());

			var queryBuilders = all.Implementing<IQueryBuilder>();
			var notQueryBuilders = all.NotImplementing<IQueryBuilder>();

			Assert.IsTrue(queryBuilders.Any());
			Assert.IsTrue(notQueryBuilders.Any());
			Assert.AreEqual(all.Count(), queryBuilders.Count() + notQueryBuilders.Count());

			var repos = all.Implementing<IRepository>();
			var notRepos = all.NotImplementing<IRepository>();

			Assert.IsTrue(repos.Any());
			Assert.IsTrue(notRepos.Any());
			Assert.AreEqual(all.Count(), repos.Count() + notRepos.Count());

			var notRepoNorQuery = all.NotImplementing<IRepository>().NotImplementing<IQueryBuilder>();
			
			Assert.IsTrue(notRepoNorQuery.Any());
			Assert.AreEqual(all.Count(), notRepoNorQuery.Count() + 
				repos.Count() + queryBuilders.Count());

			Assert.IsTrue(repos.Contains(typeof(DefaultsLocalizableWriteRepository<,>)));
		}
	}
}